package com.common.app.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.*
import com.common.app.R
import com.common.app.databinding.DialogMainPrivacyAuthorityLayoutBinding
import com.common.base.utils.ViewUtils


/**
 *
 * 作者：sosou
 *
 * 版本：1.0
 *
 * 创建日期：2023/2/18
 *
 * 描述：通用电话弹框
 *
 * 修订历史：
 *
 */
class MainPrivacyAuthorityDialog(context: Context) : Dialog(context, R.style.custom_dialog_sv),
    View.OnClickListener {
    private var binding: DialogMainPrivacyAuthorityLayoutBinding? = null

    /**
     *
     */
    private val mContext: Context

    /**
     * 点击监听
     */
    private var listener: OnMainPrivacyAuthorityListener? = null

    /**
     * 构造方法
     *
     * @param context
     */
    init {
        mContext = context
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DialogMainPrivacyAuthorityLayoutBinding.inflate(LayoutInflater.from(context))
        binding?.root?.let { setContentView(it) }
        initView()
    }

    /**
     * 初始化控件
     */
    private fun initView() {
        setCanceledOnTouchOutside(false)
        binding?.positiveButton?.setOnClickListener(this)
        binding?.negativeButton?.setOnClickListener(this)
    }

    override fun onClick(v: View) {

        //防止多次点击
        if (ViewUtils.isFastClick()) return

        binding?.let {
            dismiss()
            if (it.negativeButton == v){ listener?.onMainPrivacyAuthorityClick(0)}
        }

    }

    /**
     * @param listener
     */
    fun setListener(listener: OnMainPrivacyAuthorityListener?) {
        this.listener = listener
    }

    override fun onBackPressed() {
    }

    /**
     *
     */
    interface OnMainPrivacyAuthorityListener {
        fun onMainPrivacyAuthorityClick(mType: Int)
    }
}